package com.tdam2014.grupo3.entities;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

import org.json.JSONException;
import org.json.JSONObject;

import com.tdam2014.grupo3.flickr.util.JSONUtils;

public class PhotoSet {
	
	private String id;
	private String title;
	private Date dateCreated;
	private int countPhotos;
	
	private List<Photo> photos;
	
	public PhotoSet() {
	}
	
	public PhotoSet(JSONObject photoSetObject) throws JSONException {
		this.id = photoSetObject.getString("id");
		
		if (photoSetObject.has("title")) {
			Object titleObject = photoSetObject.get("title");
			if (titleObject instanceof String) this.title = (String) titleObject;
			else this.title = JSONUtils.getChildValue(photoSetObject, "title");
		}
		
		this.dateCreated = new Date(photoSetObject.getLong("date_create") * 1000L);
		this.countPhotos = Integer.valueOf(photoSetObject.getString("photos"));
	}
	
	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}
	
	public String getTitle() {
		return title;
	}

	public void setTitle(String title) {
		this.title = title;
	}

	public Date getDateCreated() {
		return dateCreated;
	}

	public void setDateCreated(Date dateCreated) {
		this.dateCreated = dateCreated;
	}

	public int getCountPhotos() {
		return countPhotos;
	}

	public void setCountPhotos(int countPhotos) {
		this.countPhotos = countPhotos;
	}
	
	public String getDateCreatedDateTime() {
		SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy HH:mm");
		return sdf.format(this.dateCreated);
	}
	
	public String getDateCreatedDate() {
		SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");
		return sdf.format(this.dateCreated);
	}
	
	public String getDateCreatedTime() {
		SimpleDateFormat sdf = new SimpleDateFormat("HH:mm");
		return sdf.format(this.dateCreated);
	}

	public List<Photo> getPhotos() {
		return photos;
	}

	public void setPhotos(List<Photo> photos) {
		this.photos = photos;
	}
}
